package br.com.windnfe.controller;

import java.util.List;

import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.view.Results;
import br.com.windnfe.ipersistence.IPaisDAO;
import br.com.windnfe.logic.PaisLogic;
import br.com.windnfe.model.Pais;

@Resource
public class PaisController {
	private IPaisDAO paisDAO;
	private Result result;

	public PaisController(IPaisDAO paisDAO, Result result) {
		this.paisDAO = paisDAO;
		this.result = result;
	}

	public void add(Pais pais) {
		paisDAO.add(pais);
		// new PaisLogic().teste("Diogo", this);
		// result.use(Results.json()).from(pais).serialize();
		result.nothing();
	}

	public void list() {

	}

//	public void gridList() {
//		List<Pais> paisList = paisDAO.findAll();
//		// serializa corretamente para grid.
//		result.use(Results.json()).withoutRoot().from(paisList).serialize();
//	}

	public void filtrar(String term) {
		List<Pais> paisList = new PaisLogic(this.paisDAO).filtrar(term == null ? "" : term);
		// serializa corretamente para grid.
		result.use(Results.json()).withoutRoot().from(paisList).serialize();
	}
}
